package org.cy.peoplehill.client;

import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.DecoratedStackPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.ScrollPanel;

public class MainPanel{
	private User user;
	private DecoratedStackPanel stackPanel;
	
	public MainPanel(User user){
		this.user = user;
		
		final HorizontalPanel hPanel = new HorizontalPanel();
		hPanel.setSize("100%", Window.getClientHeight()+"px");
		Window.addResizeHandler(new ResizeHandler() {
			public void onResize(ResizeEvent event) {
				int height = event.getHeight();
				hPanel.setHeight(height + "px");
			    }
			});		
		hPanel.setStylePrimaryName("hPanel");
		hPanel.setBorderWidth(5);
		
		stackPanel = new DecoratedStackPanel();
	    Label name = new Label(this.user.getName());
	    stackPanel.add(name);
	    stackPanel.setWidth("100%");
	    
	    ScrollPanel scroller = new ScrollPanel(new HTML("chatting text......"));
	    scroller.setWidth("100%");
	    
	    hPanel.add(stackPanel);
	    hPanel.add(scroller);
	    RootPanel.get().add(hPanel);	    
	    
	    //TODO: add the stack header
//	    String contactsHeader = getHeaderString(
//	        constants.cwStackPanelContactsHeader(), images.contactsgroup());
//	    stackPanel.add(createContactsItem(images), contactsHeader, true);
//	    
  
		
		//TODO: add dynamic widgets
		
	}
	
	public void setFocus(){
		//stackPanel.
	}
	
//	  private String getHeaderString(String text, ImageResource image) {
//		    // Add the image and text to a horizontal panel
//		    HorizontalPanel hPanel = new HorizontalPanel();
//		    hPanel.setSpacing(0);
//		    hPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
//		    hPanel.add(new Image(image));
//		    HTML headerText = new HTML(text);
//		    headerText.setStyleName("cw-StackPanelHeader");
//		    hPanel.add(headerText);
//
//		    // Return the HTML string for the panel
//		    return hPanel.getElement().getString();
//		  }
	  
}
